package org.dangran.util;


import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class InputStreamToFile {

    /**
     * 输入流转文件
     **/
    public static void main(String[] args) throws IOException {

        //生成File文件
        File file = new File("D:\\temp\\测试文档.doc");
        InputStream inputStream = new FileInputStream(file);

        //生成MultipartFile文件
        //contentType:文件对应的类型，可为空
        MultipartFile multipartFile = new MockMultipartFile(
                file.getName(),file.getName(),"doc", inputStream);

        inputStream.close();

        System.out.println(multipartFile.getName());
        System.out.println(multipartFile.getResource());
        System.out.println(multipartFile.getContentType());
        System.out.println(multipartFile.getOriginalFilename());


    }
}
